<template>
	<view class="wanl-page wanlshop-container wanl-list" style="backgroundSize : '100% auto';">
		<view class="wanlshop-container__head ">
			<view class="navigater flex align-center justify-between address padding-bottom-sm bg-white" style="padding-right: 25rpx;">
				<view class="search flex align-center margin-lr-xs round">
					<view class="icon text-df text-bold wanl-gray-dark">
						<text class="wlIcon-sousuo1 line-green"></text>
					</view>
					<input class="text-df" type="text" maxlength="12" confirm-type="search" placeholder-style="color: #ccc" placeholder="搜索" v-model="params.keyword" @confirm="onSearchInputConfirmed" @input="onSearchInputChanged" />
				</view>
			</view>
		</view>
		<wanl-empty v-if="goodsData.length == 0"></wanl-empty>
		<view class="product">
			<view class="item flex justify-between" v-for="(item,index) in goodsData" :key="index" @tap="$wanlshop.to(`/pages/medicalcare/homemaking/detail?id=${item.id}`)">
				<view class="hot">
					<image :src="$wanlshop.oss(item.image)" mode="aspectFill"></image>
				</view>
				<view class="left flex flex-direction">
					<view class="">
						<text class="title text-cut-2">{{item.title}}</text>
						<view class="address flex justify-start align-center">
							<view class="flex justify-start align-center" style="color:#888888;">
								<text class="text-x text-cut-1">{{item.slogan}}</text>
							</view>
						</view>
					</view>
					
					<view class="flex justify-between align-center">
						<text class="text-red text-bold price">{{item.sku[0].price}}{{item.sku[0].asprice}}</text>
						<text style="color: #888888;" class="text-xs">已售{{$wanlshop.toFormat(item.sale, 'hundred')}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="edgeInsetBottom"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	export default {
		data() {
			return {
				goodsData:[],
				params: {
					page: 1,
					keyword: ''
				},
				reload: false, //判断是否上拉
				last_page: 0,
				status: 'loading',
				contentText: {
					contentdown: '',
					contentrefresh: '正在加载..',
					contentnomore: '没有更多数据了'
				}
			};
		},
		computed: {
			...mapState(['common'])
		},
		// 监听上拉
		onPullDownRefresh() {
			this.params.page  = 1;
			this.reload = true;
			this.getServesList();
		},
		// 下拉刷新
		onReachBottom() {
			if (this.params.page >= this.last_page) {
				this.status = 'noMore';
			} else {
				this.reload = false;
				this.contentText.contentdown = '上拉显示更多';
				this.params.page = this.params.page + 1; //页码+1
				this.status = 'loading';
				this.getServesList();
			}
		},
		async onLoad(option) {
			if(option.name && !option.id) {
				this.params.keyword = option.name
			}
			this.getServesList()
		},
		methods: {
			async getServesList() {
				await uni.request({
					url: '/addons/homeking/api.goods/thali',
					method: 'post',
					data: this.params,
					success: res => {
						uni.stopPullDownRefresh();
						this.status = 'more';
						this.goodsData = this.reload ? res.data.data : this.goodsData.concat(res.data.data); //数据 追加
						this.params.page = res.data.current_page; //当前页码
						this.last_page = res.data.last_page; //总页码
					}
				});
			},
			onSearchInputChanged(event) {
				let value = event.detail.value;
				this.params.keyword = value
				this.status = 'loading';
				// 1.0.8升级
				this.goodsData = [];
				this.params.page = 1;
				this.reload = true;
				this.getServesList()
			},
			onSearchInputConfirmed(event) {
				let value = event.detail.value;
				this.params.keyword = value
				this.status = 'loading';
				// 1.0.8升级
				this.goodsData = [];
				this.params.page = 1;
				this.reload = true;
				this.getServesList()
			}
		}
	};
</script>


<style lang="scss">
	page {
		background-color: #ededed;
	}
	.wanlshop-container {
		background-repeat: no-repeat;

		&__head {
			position: relative;
			z-index: 99;
			.navigater {
				padding-left: 25rpx;
				padding-right: 25rpx;
				padding-top: 20rpx;
				.search {
					flex: 1;
					background-color: transparent;
					height: 66rpx;
					border: 2rpx solid #fff;

					.icon {
						margin: 0 20rpx;
						color: #fff;
					}

					swiper {
						height: 100%;
						width: 100%;
						margin-right: 10rpx;

						swiper-item {
							display: flex;
							align-items: center;
						}
					}
				}
			}

		}

	}

	.wanlshop-container__head .navigater .search {
		border: 3rpx solid #4CBD66;
	}
	.wanl-list .bar {
		background-color: #fff;
		margin: 20rpx 0;
		justify-content: space-around;
	}
	.product {
		// background-color: #fff;
		.item {
			background-color: #fff;
			// border-bottom: 1rpx solid rgba(182,182,182,0.5);
			margin-bottom: 10rpx;
			padding: 20rpx 30rpx;
			.hot {
				> image {
					width: 180rpx;
					height: 180rpx;
					border-radius: 10rpx;
				}
			}
			.left {
				width: calc(100% - 200rpx);
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.title {
					color: #333333;
					font-size: 32rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
				}
				.address {
					margin: 2rpx 0;
				}
				.price {
					margin-bottom: 6rpx;
					font-size: 32rpx;
				}
				.tags {
					margin-top: 4rpx;
					text {
						display: inline-block;
						color: #4CBD66;
						border: 1px solid #4CBD66;
						border-radius: 4rpx;
						margin-right: 10rpx;
						font-size: 20rpx;
						padding: 2rpx 8rpx;
						&:last-child {
							margin-right: 0;
						}
					}
				}
			}
			
		}
	}
	.filterate {
		height: 76rpx;
	}
</style>